<template>
    <div class="time-line">
        <div class="time-line-item" 
            :class="{isActive: yearIndex === index}"
            v-for="(item, index) in data"
            :key="item"
            @click="selectYear(item, index)">
            <div class="left-line">
                <div class="line"></div>
                <div class="radiuo"></div>
                <div class="line"></div>
            </div>
            <div class="right-label">{{item}}</div>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            yearIndex: 0,
            timer: null,
            intervalTime: 5000
        };
    },
    props: {
        data: {
            type: Array,
            default: () => []
        }
    },
    methods: {
        selectYear(item, index) {
            this.yearIndex = index;
        },
        // 年份轮播
        setIntervalYear() {
            clearInterval(this.timer);
            this.timer = setInterval(() => {
                this.yearIndex++;
                if(this.yearIndex >= this.data.length) {
                    this.yearIndex = 0;
                }
            }, this.intervalTime);
        }
    },
    mounted() {
        this.setIntervalYear();
    }
}
</script>
<style lang="less" scoped>
.time-line {
    box-sizing: border-box;
    height: calc(100% - 55px);
    width: 100%;
    padding: 10px;
    overflow: hidden;
    overflow-y: auto;
    .time-line-item {
        height: 72px;
        display: flex;
        align-items: center;
        .left-line {
            width: 6px;
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-right: 6px;
            .line {
                width: 1px;
                height: 28px;
                background: #E3E3E3;
                box-shadow: 0 0 4px #F0F0F0;
                border-radius: 0.5px;
            }
            .radiuo {
                width: 8px;
                height: 8px;
                border-radius: 50%;
                background: #B2B2B2;
                border: 2px solid #F0F0F0;
                margin: 4px 0;
            }
        }
        .right-label {
            height: 34px;
            line-height: 34px;
            text-align: center;
            flex: 1;
            font-size: 14px;
            color: #7B7B7B;
            letter-spacing: 0;
            cursor: pointer;
        }
        &.isActive {
            .left-line {
                .line {
                    background: #0160C0;
                    box-shadow: 0 0 4px #98CBFF;
                }
                .radiuo {
                    background: #0160C0;
                    border: 2px solid #98CBFF;
                }
            }
            .right-label {
                color: #0160c0;
                background: url(./img/bg_year.png) no-repeat center center;
            }
        }
    }
}
</style>